package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.es.domain.*;
import com.bawei.es.service.EsDocumentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author : zhangyu
 * @date 2023/11/14 16:29
 */
@RestController
@Api("Es文档管理")
@AllArgsConstructor
public class EsDocumentController {


    private EsDocumentService esDocumentService;


        /**
     * 文档插入
     * 描述：用于向数据库中插入文档
     *
     * @param documentReq 文档请求对象
     * @return 插入结果
     */
    @ApiOperation("文档插入")
    @PostMapping("/insertDocument")
    private R insertDocument(@RequestBody DocumentReq documentReq) {
        esDocumentService.insertDocument(documentReq);
    return R.ok();
    }



    @ApiOperation("/判断索引是否存在")
    @GetMapping("isExists/{indexName}")
    public R isExists(@PathVariable String indexName) {
         esDocumentService.isExists(indexName);
        return R.ok();
    }
    @ApiOperation("文档删除")
    @PostMapping("/deleteDocument")
    public R deleteDocument(@RequestBody BulkDeleteDocs documentId){
        esDocumentService.deleteDocument(documentId);
        return R.ok();
    }

    @ApiOperation("文档批量添加")
    @PostMapping("/bulkDocument")
    private R bulkDocument( @RequestBody DocumentReq bulkDocsReq){
        esDocumentService.blukDocument(bulkDocsReq);
        return R.ok();
    }

    @ApiOperation("文档修改")
    @PostMapping("/updateDocument")
    private R updateDocument(@RequestBody DocumentReq documentReq){
        esDocumentService.updateDocument(documentReq);
        return R.ok();
    }

    @ApiOperation("文档查询")
    @PostMapping("/getDocument")
    private R<EsDocsQuery> docsQuery(@RequestBody DocsQueryReq docsQueryReq){
        EsDocsQuery esDocsQuery = esDocumentService.docsQuery(docsQueryReq);
        return R.ok(esDocsQuery);
    }







}
